﻿//using System;
//using System.Globalization;
//using System.Threading;
//using System.Web.Mvc;

//using ApplicationBoilerplate.DataProvider;

//using MVCBootstrap;
//using MVCBootstrap.Web.Mvc.Controllers;

//using mvcForum.Core;
//using mvcForum.Core.Abstractions.Interfaces;
//using mvcForum.Core.Configuration;
//using mvcForum.Core.Specifications;
//using mvcForum.Web.Extensions;

//namespace mvcForum.Web.Filters {

//    public class CultureInfoFilterAttribute : ActionFilterAttribute {

//        public override void OnActionExecuting(ActionExecutingContext filterContext) {
//            base.OnActionExecuting(filterContext);

//            if (filterContext == null) {
//                throw new ArgumentNullException("filterContext");
//            }

//            if (filterContext.Controller != null) {
//                try {
//                    IConfiguration conf = DependencyResolver.Current.GetService<IConfiguration>();
//                    // Let's get the default Culture, we'll use this for the anonymous user and if anything fails.
//                    CultureInfo cu = new CultureInfo(conf.DefaultCulture);
//                    TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(conf.DefaultTimezone);

//                    // Is this authenticated request?
//                    if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated) {
//                        try {
//                            // Is this really an authenticated request?
//                            if (filterContext.RequestContext.HttpContext.User.Identity.IsAuthenticated) {
//                                // Yes!
//                                IRepository<ForumUser> fuRepo = DependencyResolver.Current.GetService<IRepository<ForumUser>>();
//                                // Let's get the ForumUser equivalent of the active user!
//                                ForumUser fu = fuRepo.ReadOne(new ForumUserSpecifications.SpecificUsername(filterContext.RequestContext.HttpContext.User.Identity.Name));
//                                // Did we get one?
//                                if (fu != null) {
//                                    // Create a CultureInfo that matches the user's settings.
//                                    cu = new CultureInfo(fu.Culture);
//                                    tzi = TimeZoneInfo.FindSystemTimeZoneById(fu.Timezone);
//                                }
//                            }
//                        }
//                        catch { }
//                    }
//                    // Set the CurrentCulture and CurrentUICulture to match what we found.
//                    Thread.CurrentThread.CurrentCulture = cu;
//                    Thread.CurrentThread.CurrentUICulture = cu;
//                    filterContext.HttpContext.Items[LocalizedBaseController.TimeZoneInfoKey] = tzi;
//                }
//                catch (Exception ex) { }
//            }
//        }
//    }
//}